#ifndef __Z_TEST_H__
#define __Z_TEST_H__

//#define DIR_HOME_UP             0       //回零点上方(在此表示远离限位电平)
//#define DIR_HOME_DOWN           1       //回零点下方（或是接近零点运动）

#define DIR_HOME_UP             1       //回零点上方(在此表示远离限位电平)
#define DIR_HOME_DOWN           0       //回零点下方（或是接近零点运动）
#define CURRENT_THREAD 					150     // 

#define HOMING_RETRACT_DIST     10       //homing_retract_dist,5mm
#define ROTATION_DISTANCE       8       //rotation_distance:8mm
#define MICROSTEPS              16      //microsteps: 16
#define POSITION_MIN            -10     //position_min: -10mm
#define POSITION_MAX            270     //position_max: 270mm
#define TEST_SPEED              15      //unit:mm/s
#define FULL_STEPS_PRE          200     //表示电机转子旋转360°所需的完整步数（如200步/转的电机，每步1.8°）
#define SUBDIVISION             (FULL_STEPS_PRE*MICROSTEPS) //200*16

//gear_ratio: 64:20，‌实际移动距离‌ = 8＊(20/64) = ‌2.5mm
#define GEAR_BIG                64
#define GEAR_SMALL              20
#define ROTATION_DIST_ACTURAL   (ROTATION_DISTANCE*GEAR_SMALL/GEAR_BIG) //2.5mm



//Z轴带热床往返运行速度：速度(RPM)的10倍
#define MOVE_VELOCITY           60*10*TEST_SPEED*GEAR_BIG/GEAR_SMALL/ROTATION_DISTANCE     //60s*10mm/2.5mm*10=240.0rpm*10

/*******************************HOMING，回零相关配置 **********************************/
//Z轴带热床回零速度：mm/s
#define HOMING_SPEED            10      //unit:mm/s
//Z轴带热床回零速度：速度(RPM)
#define HOMING_VELOCITY         60*HOMING_SPEED*GEAR_BIG/GEAR_SMALL/ROTATION_DISTANCE     //60s*10mm/2.5mm*10=240.0rpm
//回零超时，秒
//#define MOVE_TIMEOUT_HOME       (POSITION_MAX/HOMING_SPEED+2)
#define MOVE_TIMEOUT_HOME       (POSITION_MAX/HOMING_SPEED+2)
//限位电流
//#define HOMING_ENDSTOP_CURRENT  800 //800mA
#define HOMING_ENDSTOP_CURRENT  700 //700mA
#define HOMING_ENDSTOP_TIME     60  //60ms
#define HOMING_MODE             2   //2-无限制碰撞回零

#define TEST_MOVE_DISTANCE1     240    //240最佳
#define TEST_MOVE_DISTANCE2     130    //150mm
#define TEST_MOVE_NUM1          3       //280mm移动3个来回
#define TEST_MOVE_NUM2          2       //150mm移动2个来回

//根据距离mm，计算转动角度数（10倍）=3600*(dist/2.5mm)
#define DIST_TO_CNT(dist)       ((dist)*3600*GEAR_BIG/(ROTATION_DISTANCE*GEAR_SMALL))

#define ENDSTOP_FILTER_CNT      10      //endstop触发10次
#define MOVE_TIMEOUT_MAX        (POSITION_MAX/TEST_SPEED+2)
#define MOVE_TIMEOUT_DIST1      (TEST_MOVE_DISTANCE1/TEST_SPEED+2)
#define MOVE_TIMEOUT_DIST2      (TEST_MOVE_DISTANCE2/TEST_SPEED+2)

void tst_z_move_start(void);
void tst_z_move_task(void);
void tst_z_test_init(void);
#endif
